<html><head><title>Json.pb</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<pre><font face="Courier New, Courier, mono"size="2"><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font><font color="#006666">;   PureBasic - Json
</font><font color="#006666">;
</font><font color="#006666">;    (c) Fantaisie Software
</font><font color="#006666">;
</font><font color="#006666">; ------------------------------------------------------------
</font><font color="#006666">;
</font>
<font color="#924B72">#JSON_Create</font> = 0
<font color="#924B72">#JSON_Parse</font> = 1


<font color="#006666">; Build JSON data from scratch
</font><font color="#006666">;
</font><b><font color="#006666">If</font></b> <font color="#006666">CreateJSON</font>(<font color="#924B72">#JSON_Create</font>)
  Person =<font color="#006666"> SetJSONObject</font>(<font color="#006666">JSONValue</font>(<font color="#924B72">#JSON_Create</font>))
<font color="#006666">  SetJSONString</font>(<font color="#006666">AddJSONMember</font>(Person, "FirstName"), "John")
<font color="#006666">  SetJSONString</font>(<font color="#006666">AddJSONMember</font>(Person, "LastName"), "Smith")
<font color="#006666">  SetJSONInteger</font>(<font color="#006666">AddJSONMember</font>(Person, "Age"), 42)
  
  Values =<font color="#006666"> SetJSONArray</font>(<font color="#006666">AddJSONMember</font>(Person, "Values"))
  <b><font color="#006666">For</font></b> i = 1 <b><font color="#006666">To</font></b> 5
<font color="#006666">    SetJSONInteger</font>(<font color="#006666">AddJSONElement</font>(Values),<font color="#006666"> Random</font>(256))
  <b><font color="#006666">Next</font></b> i
  
  <b><font color="#006666">Debug</font></b> "---------- Compact format ----------"
  <b><font color="#006666">Debug</font></b> ""
  <b><font color="#006666">Debug</font></b> <font color="#006666">ComposeJSON</font>(<font color="#924B72">#JSON_Create</font>)
  <b><font color="#006666">Debug</font></b> ""
  <b><font color="#006666">Debug</font></b> "---------- Pretty-Printed format ----------"
  <b><font color="#006666">Debug</font></b> ""
  <b><font color="#006666">Debug</font></b> <font color="#006666">ComposeJSON</font>(<font color="#924B72">#JSON_Create</font>, <font color="#924B72">#PB_JSON_PrettyPrint</font>)
  <b><font color="#006666">Debug</font></b> ""
<b><font color="#006666">EndIf</font></b>


<font color="#006666">; Read JSON data from a string
</font><font color="#006666">;
</font>Input$ = "[1, 3, 5, 7, null, 23, 25, 27]"
<b><font color="#006666">If</font></b> <font color="#006666">ParseJSON</font>(<font color="#924B72">#JSON_Parse</font>, Input$)
  <b><font color="#006666">NewList</font></b> <font color="#006666">Numbers</font>()
<font color="#006666">  ExtractJSONList</font>(<font color="#006666">JSONValue</font>(<font color="#924B72">#JSON_Parse</font>),<font color="#006666"> Numbers</font>())
  
  <b><font color="#006666">Debug</font></b> "---------- Extracting values ----------"
  <b><font color="#006666">Debug</font></b> ""
  <b><font color="#006666">ForEach</font></b> <font color="#006666">Numbers</font>()
    <b><font color="#006666">Debug</font></b> <font color="#006666">Numbers</font>()
  <b><font color="#006666">Next</font></b> 
<b><font color="#006666">EndIf</font></b>


</font></pre>
</body></html>
